package com.study.kt._04project.game_tank.model

import com.study.kt._04project.game_tank.Config
import com.study.kt._04project.game_tank.business.Destoryable
import org.itheima.kotlin.game.core.Painter

/**
 * 爆炸物
 * 爆炸物播放完毕要被回收，所以需要有可回收能力
 */
class Blast(override val x: Int, override val y: Int) : Destoryable {

    override val width: Int = Config.block
    override val height: Int = Config.block

    //所有爆炸物的图片
    val imagePath = arrayListOf<String>()
    //当前绘制的爆炸物
    var index: Int = 0

    init {
        (1..32).forEach {
            imagePath.add("img/blast_$it.png")
        }
    }

    override fun draw() {
        //防止越界
        var i = index % imagePath.size
        Painter.drawImage(imagePath[i], x, y)
        index++
    }

    override fun isDestory(): Boolean {
        //当爆炸物播放一次后消失
        return index >= imagePath.size
    }
}